﻿<UserControl x:Class="Modules.Artists.Views.ArtistsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:converters="clr-namespace:Modules.Artists.Converters"
             xmlns:commonControls="clr-namespace:Common.Controls.Controls;assembly=Common.Controls"
             xmlns:pagerCommands="clr-namespace:Common.Controls.Controls;assembly=Common.Controls"
             xmlns:commands="clr-namespace:Common.Commands;assembly=Common.Commands"
             xmlns:prismCommands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
             xmlns:prismRegions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
             mc:Ignorable="d" commands:Loaded.Command="{Binding ViewLoadedCommand}"
             x:Name="artistsView"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Common.Dialogs;component/Styles/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <ContextMenu x:Key="ArtistContextMenu">
                <MenuItem Header="Create new artist" commands:MenuItemClick.Command="{Binding CreateArtistCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_add_48x48.png" Style="{StaticResource MenuIconStyle}"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Edit artist" commands:MenuItemClick.Command="{Binding EditArtistCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_edit_48x48.png" Style="{StaticResource MenuIconStyle}"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Remove artist" commands:MenuItemClick.Command="{Binding RemoveArtistCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_remove_48x48.png" Style="{StaticResource MenuIconStyle}"/>
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Create album for artist" commands:MenuItemClick.Command="{Binding CreateAlbumCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_album_48x48.png" Style="{StaticResource MenuIconStyle}"/>
                    </MenuItem.Icon>
                </MenuItem>
            </ContextMenu>

            <Style x:Key="AnimatedTextBlockStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="Foreground" Value="Gray"/>
                <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="0" ScaleY="0" />
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsLoadingAlbums}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetProperty="RenderTransform.ScaleX"
                                        To="1" Duration="0:0:0.0" DecelerationRatio="1" />
                                    <DoubleAnimation
                                          Storyboard.TargetProperty="RenderTransform.ScaleY"
                                          To="1" Duration="0:0:0.0" DecelerationRatio="1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                      Storyboard.TargetProperty="RenderTransform.ScaleX"
                                      From="1" Duration="0:0:0.40" DecelerationRatio="1" />
                                    <DoubleAnimation
                                      Storyboard.TargetProperty="RenderTransform.ScaleY"
                                      From="1" Duration="0:0:0.40" DecelerationRatio="1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <DataTemplate x:Key="ArtistTemplate">
                <TextBlock Text="{Binding Name}"/>
            </DataTemplate>

            <DataTemplate x:Key="AlbumTemplate">
                <TextBlock Text="{Binding Name}"/>
            </DataTemplate>

            <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
            <converters:BoolToOpacityConverter x:Key="BoolToOpacityConverter"/>

        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" 
          commonControls:BusyIndicatorBehavior.BusyState="{Binding IsBusy}"
          commonControls:BusyIndicatorBehavior.AddMargins="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ToolBarTray Grid.Row="0" Grid.ColumnSpan="2">
            <ToolBar HorizontalAlignment="Left">
                <Button Margin="2"
                                Style="{StaticResource ToolbarImageButtonStyle}"
                                ToolTip="Create new artist"
                                prismCommands:Click.Command="{Binding CreateArtistCommand}"
                                      >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_add_48x48.png" Width="48" Height="48" Stretch="Fill"/>
                    </Button.Content>
                </Button>
                <Button Margin="2"
                                Style="{StaticResource ToolbarImageButtonStyle}"
                                ToolTip="Edit selected artist"
                                prismCommands:Click.Command="{Binding EditArtistCommand}"
                                      >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_edit_48x48.png" Stretch="Fill"/>
                    </Button.Content>
                </Button>
                <Button Margin="2"
                                Style="{StaticResource ToolbarImageButtonStyle}"
                                ToolTip="Remove selected artist"
                                prismCommands:Click.Command="{Binding RemoveArtistCommand}"
                                      >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/Conductor_remove_48x48.png" Stretch="Fill"/>
                    </Button.Content>
                </Button>
            </ToolBar>
            <ToolBar HorizontalAlignment="Left">
                <Button Margin="2"
                                    Style="{StaticResource ToolbarImageButtonStyle}"
                                    ToolTip="Create new album for selected artist"
                                    prismCommands:Click.Command="{Binding CreateAlbumCommand}"
                                          >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/CD_add_48x48.png" Width="48" Height="48" Stretch="Fill"/>
                    </Button.Content>
                </Button>
                <Button Margin="2"
                                    Style="{StaticResource ToolbarImageButtonStyle}"
                                    ToolTip="Edit selected album"
                                    prismCommands:Click.Command="{Binding EditAlbumCommand}"
                                          >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/CD_edit_48x48.png" Stretch="Fill"/>
                    </Button.Content>
                </Button>
                <Button Margin="2"
                                    Style="{StaticResource ToolbarImageButtonStyle}"
                                    ToolTip="Remove selected album"
                                    prismCommands:Click.Command="{Binding RemoveAlbumCommand}"
                                          >
                    <Button.Content>
                        <Image Source="/Common.Dialogs;component/Images/CD_remove_48x48.png" Stretch="Fill"/>
                    </Button.Content>
                </Button>
            </ToolBar>
        </ToolBarTray>

        <commonControls:FilterControl Grid.Row="1" Grid.ColumnSpan="2" Margin="4"
                                          FilterFields="{Binding Fields}"
                                          SelectedFilterField="{Binding SelectedField,Mode=TwoWay}"
                                          SelectedFilterValue="{Binding SelectedValue,Mode=TwoWay}"
                                          ItemContainerStyle="{StaticResource GeneralComboBoxItemStyle}"
                                          />

        <GroupBox Header="Artists" Grid.Row="2" Grid.Column="0">
            <ListView x:Name="ArtistsListView" 
                      ItemsSource="{Binding ArtistsCollection}" 
                      SelectedItem="{Binding CurrentArtist,Mode=TwoWay}"
                      ItemContainerStyle="{StaticResource GeneralListViewItemStyle}"
                      ItemTemplate="{StaticResource ArtistTemplate}" ContextMenu="{StaticResource ArtistContextMenu}"
                      commands:MouseDoubleClick.Command="{Binding EditArtistCommand}"/>
        </GroupBox>



        <GroupBox Header="Albums" Grid.Row="2" Grid.Column="1">
            <Grid x:Name="ArtistAlbumsLayout">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ListView x:Name="AlbumsListView" Grid.Row="0" Opacity="{Binding IsLoadingAlbums,Converter={StaticResource BoolToOpacityConverter}}"
                  ItemsSource="{Binding ArtistAlbums}" 
                  SelectedItem="{Binding CurrentAlbum,Mode=TwoWay}"
                  ItemContainerStyle="{StaticResource GeneralListViewItemStyle}"
                  ItemTemplate="{StaticResource AlbumTemplate}"
                  commands:MouseDoubleClick.Command="{Binding EditAlbumCommand}"/>
                <TextBlock Text="Loading albums..." FontWeight="Bold" FontSize="14"
                           VerticalAlignment="Center" HorizontalAlignment="Center"
                           Style="{StaticResource AnimatedTextBlockStyle}"
                           Grid.Row="0"/>
            </Grid>
        </GroupBox>


        <Grid x:Name="PagerLayout" Grid.Row="3" Grid.ColumnSpan="2">
            <commonControls:DataPager Margin="4"
                                      HorizontalAlignment="Left"
                                      ItemsPerPage="{Binding LoadOptions.MaxResults}" VisiblePagesCount="3" TotalItems="{Binding ArtistsCount}"
                                      pagerCommands:PageChanged.Command="{Binding PageChangedCommand}"/>
        </Grid>
    </Grid>
</UserControl>
